package top.lishuoboy.spring.aop.spring_aspects;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

// 2.第二个增强的类
@Slf4j
@Component
@Aspect
// 结论：排序号越小，优先级越高，通知越靠”被增强的方法“外围
@Order(1)  // value 默认为 Integer.MAX_VALUE;
public class Student20Proxy2 {
    @Around(value = "Student20Proxy.myCommonPointcut()")
    public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        log.warn("前置环绕通知");
        // 被增强的方法执行
        proceedingJoinPoint.proceed();
        log.warn("后置环绕通知");  // 有异常时不执行
    }

    @Before(value = "Student20Proxy.myCommonPointcut()")
    public void before() {
        log.warn("前置通知");
    }

    @AfterReturning(value = "Student20Proxy.myCommonPointcut()", pointcut = "")
    public void afterReturning() {
        log.warn("返回通知");
    }

    @AfterThrowing(value = "Student20Proxy.myCommonPointcut()", pointcut = "")
    public void afterThrowing() {
        log.warn("异常通知");
    }

    @After(value = "Student20Proxy.myCommonPointcut()")
    public void after() {
        log.warn("后置通知");  // 后置通知（最终通知），有没有异常都会执行，类似 finally
    }
}